package com.sxpi.zixun.controller.adminpermission;

import com.sxpi.zixun.bo.AdminPermissionBo;
import com.sxpi.zixun.common.anno.IgnoreToken;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.AdminPermission;
import com.sxpi.zixun.service.adminpermission.IAdminPermissionService;
import com.sxpi.zixun.vo.StatusUpdateVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/8/27 16:13
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="后台权限管理",tabname="kss_permission")
public class AdminPermissionController extends BaseController {

    private final IAdminPermissionService adminpermissionService;

    /**
     * 查询分类的接口信息-tree
     * 这里是递归查询所有的权限，让角色去授予权限使用
     *
     * @return
     */
    @PostMapping("/adminpermission/tree")
    @PugDoc(name="查询菜单和权限信息tree")
    @IgnoreToken
    public List<AdminPermission> permissionTree() {
        return adminpermissionService.findAdminPermissionTree();
    }

    /**
     * 查询分类的接口信息-tree
     * 这个是查询后台左边侧边栏导航
     * @return
     */
    @PostMapping("/adminpermission/menu/tree")
    @PugDoc(name="查询后台菜单信息")
    public List<AdminPermission> permissionMenuTree() {
        return adminpermissionService.findAdminPermissionMenuTree();
    }

    /**
     * 保存和修改后台权限管理
     * @param adminpermission
     * @return
     */
    @PostMapping("/adminpermission/saveupdate")
    @PugDoc(name="保存和修改后台权限管理")
    public AdminPermissionBo saveUpdateAdminPermission(@RequestBody AdminPermission adminpermission) {
        return adminpermissionService.saveUpdateAdminPermission(adminpermission);
    }

    /**
     * 根据后台权限管理id删除后台权限管理
     * @param id
     * @return
     */
    @PostMapping("/adminpermission/delete/{id}")
    @PugDoc(name="根据后台权限管理id删除后台权限管理")
    public int deleteAdminPermissionById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id,ResultStatusEnum.ID_NOT_EMPTY);
        return adminpermissionService.deleteAdminPermissionById(new Long(id));
    }

    /**
     * 用于状态更新
     * @param statusUpdateVo
     * @return
     */
    @PostMapping("/adminpermission/update")
    @PugDoc(name = "用于状态更新")
    public boolean updateAdminPermission(@RequestBody StatusUpdateVo statusUpdateVo) {
        return adminpermissionService.updateAdminPermission(statusUpdateVo);
    }
}
